// pages/serviceDetails/serviceDetails.js
const util = require("../../utils/util")
import wxParse from '../../wxParse/wxParse.js'; // 富文本插件
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgPath: "/images",
    currentTab: 0,
    ids:0,
    sleft: "", //横向滚动条位置
    list: [{
        id: 1,
        title: '免费纸尿裤',
        content: '<div><p class="reply">暂无数据</p></div>',
        time: '2022-05-20',
        icon: 'http://qnstatic.lianhequnmei.com/images/20221216/icon1.png',
        on_icon: 'http://qnstatic.lianhequnmei.com/images/20221216/icon_on1.png'
      },
      {
        id: 2,
        title: '线上早教课',
        content: '<div><p class="reply">暂无数据</p></div>',
        time: '2019-05-20',
        icon: 'http://qnstatic.lianhequnmei.com/images/20221216/icon2.png',
        on_icon: 'http://qnstatic.lianhequnmei.com/images/20221216/icon_on2.png'
      },
      {
        id: 3,
        title: '宝宝成长派对',
        content: '<div><p class="reply">暂无数据</p></div>',
        time: '2022-05-20',
        icon: 'http://qnstatic.lianhequnmei.com/images/20221216/icon3.png',
        on_icon: 'http://qnstatic.lianhequnmei.com/images/20221216/icon_on3.png'
      },
      {
        id: 4,
        title: '在线育儿咨询',
        content: '<div><p class="reply">暂无数据</p></div>',
        time: '2022-05-20',
        icon: 'http://qnstatic.lianhequnmei.com/images/20221216/icon4.png',
        on_icon: 'http://qnstatic.lianhequnmei.com/images/20221216/icon_on4.png'
      },
      {
        id: 5,
        title: '专属成长计划',
        content: '<div><p class="reply">暂无数据</p></div>',
        time: '2022-05-20',
        icon: 'http://qnstatic.lianhequnmei.com/images/20221216/icon5.png',
        on_icon: 'http://qnstatic.lianhequnmei.com/images/20221216/icon_on5.png'
      },
      {
        id: 6,
        title: '30天退换',
        content: '<div><p class="reply">暂无数据</p></div>',
        time: '2022-05-20',
        icon: 'http://qnstatic.lianhequnmei.com/images/20221216/icon6.png',
        on_icon: 'http://qnstatic.lianhequnmei.com/images/20221216/icon_on6.png'
      },
    ]


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

    let ids = options.id;
    let that = this;
    this.setData({
      imgPath: util.getImgPath(),
      ids: Number(options.id)
    })
         //6大服务介绍
          this.setData({
            list: []
          })
         const api = require("../../api/api");
         api.card.getServicesList({
           success(res) {
          if(res.data.code == 0){
              for (let i = 0; i < res.data.data.length; i++) {
                wxParse.wxParse('content' + i, 'html', res.data.data[i].content, that);
                //delete list[i].content;
                if (i === res.data.data.length - 1) {
                  wxParse.wxParseTemArray("WxParseListArr", 'content', res.data.data.length, that)
                }
                that.data.list.push({
                  id: res.data.data[i].id,
                  content: res.data.data[i].content,
                  title: res.data.data[i].title,
                  icon:res.data.data[i].icon,
                  on_icon:res.data.data[i].on_icon,
                })
              }
              that.setData({
                list: that.data.list,
                currentTab:that.data.ids,
              })
              if(that.data.ids>3){
                that.setData({
                  sleft: 1000,
                })
              }

             }
            
           }
         })





  },
  handleTabChange(e) {
    let {
      current
    } = e.target.dataset;
    if (this.data.currentTab == current || current === undefined) return;
    this.setData({
      currentTab: current,
      //ids:current
    });
  },
  handleSwiperChange(e) {
    this.setData({
      currentTab: e.detail.current,
    });
    this.getScrollLeft();
  },
  getScrollLeft() {
    const query = wx.createSelectorQuery();
    query.selectAll(".item").boundingClientRect();
    query.exec((res) => {
      let num = 0;
      for (let i = 0; i < this.data.currentTab; i++) {
        num += res[0][i].width;
      }
      this.setData({
        sleft: Math.ceil(num),
      });
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})